﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace KLTN
{
    public class CCamera
    {
        private Matrix view;
        private Matrix projection;
        public Matrix View
        {
            get { return view; }
            protected set { view = value; generateFrustum(); }
        }
        public Matrix Projection 
        {
            get{return projection;}
           protected set { projection = value; generateFrustum(); }
        }
        protected GraphicsDevice graphicDevice { get; set; }

        public BoundingFrustum Frustum { get;private set; }       

        private void generateFrustum()
        {
            Matrix viewProjection = View * Projection;
            Frustum = new BoundingFrustum(viewProjection);//
        }
        public CCamera(GraphicsDevice graphic)
        {
            this.graphicDevice = graphic;
            generatePerspectiveProjectionMatrix(MathHelper.PiOver4);
        }

        private void generatePerspectiveProjectionMatrix(float FiledOfView)
        {
            PresentationParameters pp= graphicDevice.PresentationParameters;
            float aspectRatio= (float)(pp.BackBufferWidth)/pp.BackBufferHeight;
            this.Projection = Matrix.CreatePerspectiveFieldOfView(FiledOfView, aspectRatio, 0.1f, 1000000.0f);
        }

        public virtual void Update()
        { 
            
        }
        public bool BoudingVolumeslnView(BoundingSphere sphere)
        {
            return (Frustum.Contains(sphere) != ContainmentType.Disjoint);//
        }
    }
}
